<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改密码</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            background-color: white;
            padding: 50px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
        }
        .container h2 {
            margin-bottom: 20px;
        }
        .container input {
            width: calc(100% - 22px);
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .container button {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            background-color: #ff5000;
            border: none;
            color: white;
            border-radius: 5px;
            cursor: pointer;
        }
        .container button:hover {
            background-color: #e04a00;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>修改密码</h2>
    <input type="text" placeholder="账号" id="account">
    <input type="password" placeholder="新密码" id="new-password">
    <input type="password" placeholder="确认密码" id="confirm-password">
    <button onclick="changePassword()">确认修改</button>
</div>

<script>
    function changePassword() {
        const account = document.getElementById('account').value;
        const newPassword = document.getElementById('new-password').value;
        const confirmPassword = document.getElementById('confirm-password').value;

        if (newPassword !== confirmPassword) {
            alert('两次输入的密码不匹配');
            return;
        }

        fetch('/users/change-password', {
            method: 'PATCH',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ account: account, newPassword: newPassword }),
        })
            .then(response => {
                if (response.ok) {
                    alert('密码修改成功');
                    // 跳转到登录页面或其他页面
                    window.location.href = 'login'; // 替换为实际的登录页面URL
                } else {
                    throw new Error('修改密码失败');
                }
            })
            .catch(error => {
                alert('修改密码失败：' + error.message);
            });
    }
</script>
</body>
</html>
